package com.apache.funds.service.plugins;

import java.util.Map;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.funds.entity.SvmUser;
import com.apache.funds.manager.SvmUserManager;
import com.apache.funds.util.Constants;

/**  
 * 查询我的虚拟账户信息（根据userId查询）
 * @author xhe 创建时间：2015-12-06      
 */
public class FundsMyAccountByUserIdPlugin implements PluginConnector {
	private Logger log = LoggerFactory.getLogger(getClass());
	private SvmUserManager svmUserManager;

	@SuppressWarnings("unchecked")
	@Override
	public Object execute(ParamsVo pvo) throws Exception {
		ResultEntity entity = new ResultEntity();
		entity.setResult("true");
		entity.setMessage("查询失败");

		Map<String, String> prarmMap = pvo.getParams();
		//校验参数
		String userId = prarmMap.get("userId");//一般是UCT用户的主键(在开户的时候存入）
		if (Validator.isNull(userId)) {
			entity.setMessage(Constants.Msg.F003);
			return entity;
		}
		ParamsVo<SvmUser> voU = new ParamsVo<SvmUser>();
		voU.setInfoId(userId);
		SvmUser selectUser = (SvmUser) svmUserManager.getInfoById(voU);
		if (selectUser == null) {
			log.info("此[" + userId + "]未开通虚拟账户");
			entity.setMessage(Constants.Msg.F004);
			return entity;
		}
		entity.setMessage(Constants.Msg.F000+",查询完成");
		entity.setEntity(JSONObject.fromObject(selectUser));
		return entity;
	}

	public void setSvmUserManager(SvmUserManager svmUserManager) {
		this.svmUserManager = svmUserManager;
	}

}
